package com.example.administrator.testdemo.ZDY;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.text.Layout;
import android.util.AttributeSet;
import android.widget.EditText;

public class MutilUnderEditText extends EditText {


    private Paint mPaint;

    private Rect rect;

    public MutilUnderEditText(Context context) {
        super(context);
        initView();
    }



    public MutilUnderEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public MutilUnderEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }


    private void initView() {
        mPaint = new Paint();
        rect = new Rect();

        mPaint.setColor(Color.BLACK);

        mPaint.setStrokeWidth(1);

        setTextSize(30);
    }

    @Override
    public void draw(Canvas canvas) {

        Rect r = rect;

        Paint paint = mPaint;

        Layout layout = getLayout();

        if (!canvas.getClipBounds(r))
            return;



        int count = layout.getLineCount();

        float textSize = getTextSize();

        int lineHeight = getLineHeight();

        int height = getHeight() - getPaddingBottom() - getPaddingTop();

        int n = height % lineHeight == 0 ? height / lineHeight : height / lineHeight + 1;
        if (count < n) {
            count = n;
        }

        float pt = textSize / 6;

        for (int i = 1; i <= count; i++) {
            int y = (int) (lineHeight * i + pt);
            canvas.drawLine(getLeft(), y , getRight(), y, paint);
        }

        super.draw(canvas);
    }
}
